import events.MyEvent;
import flash.net.FileReference;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;

import mx.collections.ArrayCollection;
import mx.controls.Alert;

public var fileType:String="xml";

[Bindable]
public var FileFilters:Array=new Array();
private var lastString:String;
private function handleScanTypeClick(e:MouseEvent):void
{
	switch(e.target.id)
	{
		case "allType":
			this.types.enabled=false;
			this.FileFilters=null;
			this.dispatchEvent(new MyEvent("typeChange",null));
			break;
		case "customType":
			this.types.enabled=true;
			break;
	}
}

private function handleTypesKeyBoardInput(e:KeyboardEvent):void
{
	
	if (e.charCode==13) 
	{
		typesInputListener();
	}
}

private function xmljsonClick(e:MouseEvent):void
{
	switch(e.target.id)
	{
		case "xmlType":
			if(fileType=="xml")return;
			fileType="xml";
			break;
		case "jsonType":
			if(fileType=="json")return;
			fileType="json";
			break;
	}
	this.dispatchEvent(new MyEvent("xmljson",this.fileType));
}

private function handleSaveClick(e:MouseEvent):void
{
	this.dispatchEvent(new MyEvent("save",this.fileType));
}

private function typesInputListener():void
{
	
	var str:String=types.text;
	if(str==this.lastString)return;
	if(str.slice(str.length-1)!=";")
	{
		Alert.show("格式错误","错误");
		return;
	}
	this.FileFilters=null;
	this.FileFilters=new Array();
	this.FileFilters=str.split(";");
	this.dispatchEvent(new MyEvent("typeChange",this.FileFilters));
	this.lastString=str;
}